﻿using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;

namespace QLNXe
{
    public partial class VeXe : Form
    {
        float ScreenResolution = 96.0f;

        public void GetData(TextBox txtBienSo, TextBox loaiVe, TextBox giaVe)
        {
            lblBienSo.Text = txtBienSo.Text;
            lblGiaVe.Text = giaVe.Text;
            lblLoaiVe.Text = loaiVe.Text;
        }

        public VeXe()
        {
            InitializeComponent();
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            PrinterResolution pr = e.PageSettings.PrinterResolution;

            DrawForm(e.Graphics, pr.X, pr.Y);
        }

        private void DrawForm(Graphics g, int resX, int resY)
        {
            g.FillRectangle(new SolidBrush(this.BackColor), 0, 0, this.Width, this.Height);

            foreach (Control c in Controls)
            {
                string strType = c.GetType().ToString().Substring(c.GetType().ToString().LastIndexOf(".") + 1);

                switch (strType)
                {
                    case "Label":
                        Label l = (Label)c;
                        g.DrawString(l.Text, l.Font, new SolidBrush(l.ForeColor), l.Left + 2, l.Top + l.Height / 2 - g.MeasureString("a", l.Font).Height / 2, new StringFormat());
                        break;
                }
            }
        }

        private void printPreviewToolStripMenuItem_Click(object sender, System.EventArgs e)
        {
            printPreviewDialog1.ShowDialog();
        }

        private void VeXe_Paint(object sender, PaintEventArgs e)
        {
            ScreenResolution = e.Graphics.DpiX;
        }

        private void VeXe_Load(object sender, System.EventArgs e)
        {
            lblNgay.Text = DateTime.Now.ToShortDateString();
        }
    }
}